package com.boot.mgt.service.impl

import com.alibaba.fastjson.JSON
import com.boot.core.result.ResultTo
import com.boot.core.util.ManagerKit
import com.boot.mgt.dao.mysql.RegionGlbmMapper
import com.boot.mgt.dao.mysql.TaAccidentImageMapper
import com.boot.mgt.dao.mysql.TaPoliceSituationMonitoringMapper
import com.boot.mgt.dao.mysql.TaPoliceSituationMonitoringTransactionMapper
import com.boot.mgt.model.TaAccidentImage
import com.boot.mgt.model.vo.TaPoliceSituationMonitoringVo
import com.boot.mgt.service.RegionGlbmService
import com.boot.mgt.service.TaPoliceService
import com.boot.mgt.service.TaPoliceSituationMonitoringService
import com.github.pagehelper.PageHelper
import com.github.pagehelper.PageInfo
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl
import org.apache.commons.collections.CollectionUtils.*
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.math.BigDecimal
import java.math.RoundingMode
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.stream.Collectors
import kotlin.collections.ArrayList
import kotlin.collections.HashMap

@AutoJsonRpcServiceImpl
@Service
class TaPoliceSituationMonitoringServiceImpl : TaPoliceSituationMonitoringService {

    @Autowired
    private lateinit var taPoliceSituationMonitoringMapper : TaPoliceSituationMonitoringMapper

    @Autowired
    private lateinit var taPoliceSituationMonitoringTransactionMapper : TaPoliceSituationMonitoringTransactionMapper

    @Autowired
    private lateinit var taPoliceService: TaPoliceService

    @Autowired
    protected lateinit var accidentImageMapper: TaAccidentImageMapper

    @Autowired
    private lateinit var regionGlbmService: RegionGlbmService

    @Autowired
    private lateinit var regionGlbmMapper: RegionGlbmMapper

    companion object {
        private val log: Logger = LoggerFactory.getLogger(this::class.java)
    }


    override fun list(page_index: Int?, page_size: Int?, map: MutableMap<String, Any>): ResultTo {
        PageHelper.startPage<Any>(page_index ?: 1, page_size ?: 20)
        map["orgNum"] = ManagerKit.getOrgNum()
        val list = taPoliceSituationMonitoringMapper.searchTaPoliceSituationMonitoringList(map)
        val pageInfo = PageInfo(list)
        return ResultTo().apply {
//            this["report_list"] = list
            this["page_index"] = page_index ?: 0
            this["page_amount"] = pageInfo.pages
            this["page_total"] = pageInfo.total
        }
    }

    override fun searchTaPoliceSituationMonitoringList(map: Map<String, Any>?): List<TaPoliceSituationMonitoringVo?>? {
        try {
            return taPoliceSituationMonitoringMapper.searchTaPoliceSituationMonitoringList(map);
        } catch (e: Exception) {
            e.printStackTrace();
            log.info("searchTaPoliceSituationMonitoringList: {}", e);
        }
        return emptyList();
    }

    override fun searchTaPoliceSituationMonitoringTimeRange(id: Long?, regionId: String?): HashMap<String, TaPoliceSituationMonitoringVo?>? {
        val situationMonitoring:HashMap<String, TaPoliceSituationMonitoringVo?> = HashMap<String, TaPoliceSituationMonitoringVo?>()
        var today = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now())
        var month = DateTimeFormatter.ofPattern("yyyyMM").format(LocalDate.now())
        var year = DateTimeFormatter.ofPattern("yyyy").format(LocalDate.now())
        var regionValLike = regionId?.let { taPoliceService.consRegion(it) } as String
        var situationMonitoringToday = this.detailSum(id, today, regionValLike)
        var situationMonitoringMonth = this.detailSum(id, month, regionValLike)
        var situationMonitoringYear = this.detailSum(id, year, regionValLike)
        situationMonitoring["today"] = situationMonitoringToday
        situationMonitoring["month"] = situationMonitoringMonth
        situationMonitoring["year"] = situationMonitoringYear
        return situationMonitoring;
    }

    override fun detail(id: Long?, timeTag: String?, regionId: String?): TaPoliceSituationMonitoringVo? {
        return taPoliceSituationMonitoringMapper.detail(id, timeTag, regionId);
    }

    override fun detailSum(id: Long?, timeTag: String?, regionId: String?): TaPoliceSituationMonitoringVo? {
        return taPoliceSituationMonitoringMapper.detailSum(id, timeTag, regionId);
    }

    override fun update(taPoliceSituationMonitoringVo: TaPoliceSituationMonitoringVo): Int {
        try {
            return taPoliceSituationMonitoringMapper.update(taPoliceSituationMonitoringVo);
        } catch (e: Exception) {
            log.info("TaPoliceSituationMonitoringServiceImpl.update: {}", e);
        }
        return 0
    }

    override fun insert(taPoliceSituationMonitoringVo: TaPoliceSituationMonitoringVo): Int {
        try {
            return taPoliceSituationMonitoringMapper.insert(taPoliceSituationMonitoringVo);
        } catch (e: Exception) {
            log.info("TaPoliceSituationMonitoringServiceImpl.insert: {}", e);
        }
        return 0
    }

    override fun delete(map: Map<String, Any>?): Int {
        try {
            return taPoliceSituationMonitoringMapper.delete(map);
        } catch (e: Exception) {
            log.info("TaPoliceSituationMonitoringServiceImpl.delete: {}", e);
        }
        return 0
    }

    override fun doMonitorAction(actionTagMap: Map<String, Any?>): Int {
        val timeTagToday = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now());
        val timeTagTimestamp = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now())
        var taPoliceSituationMonitoringTransaction: TaPoliceSituationMonitoringVo = TaPoliceSituationMonitoringVo()
        var taPoliceSituationMonitoring = taPoliceSituationMonitoringMapper.detail(null, timeTagToday, actionTagMap["regionId"] as String)
        if(taPoliceSituationMonitoring!=null && !"".equals(taPoliceSituationMonitoring)) {
        } else {
            taPoliceSituationMonitoring = TaPoliceSituationMonitoringVo()
        }
        for(key in actionTagMap.keys) {
            // @param id
            if(key == "id") {
                taPoliceSituationMonitoring.id = taPoliceSituationMonitoring.id
            }
            // 管理部门Id
            if(key == "regionId") {
                taPoliceSituationMonitoring.regionId = actionTagMap["regionId"] as String
                taPoliceSituationMonitoringTransaction.regionId = actionTagMap["regionId"] as String
            }
            // %Y%m%d
            taPoliceSituationMonitoring.timeTag = timeTagToday
            taPoliceSituationMonitoringTransaction.timeTag = timeTagTimestamp
            /*if(key == "timeTag") {
                taPoliceSituationMonitoring.timeTag = timeTagToday
            }*/
            // 当前出警量(实时变化)
            if(key == "casesAcceptedActionCurrent") {
                taPoliceSituationMonitoring.casesAcceptedActionCurrent = taPoliceSituationMonitoring.casesAcceptedActionCurrent?.plus(1)
                taPoliceSituationMonitoringTransaction.casesAcceptedActionCurrent = 1
            }
            // 现场处置量(实时变化)
            if(key == "casesSceneDisposal") {
                taPoliceSituationMonitoring.casesSceneDisposal = taPoliceSituationMonitoring.casesSceneDisposal?.plus(1)
                taPoliceSituationMonitoringTransaction.casesSceneDisposal = 1
            }
            // 接警量
            if(key == "casesAcceptedCalled") {
                taPoliceSituationMonitoring.casesAcceptedCalled = taPoliceSituationMonitoring.casesAcceptedCalled?.plus(1)
                taPoliceSituationMonitoringTransaction.casesAcceptedCalled = 1
            }
            // 出警量
            if(key == "casesAcceptedAction") {
                taPoliceSituationMonitoring.casesAcceptedAction = taPoliceSituationMonitoring.casesAcceptedAction?.plus(1)
                taPoliceSituationMonitoringTransaction.casesAcceptedAction = 1
            }
            // 受理案件量
            if(key == "dealAccepted") {
                taPoliceSituationMonitoring.dealAccepted = taPoliceSituationMonitoring.dealAccepted?.plus(1)
                taPoliceSituationMonitoringTransaction.dealAccepted = 1
            }
            // 快赔案件量
            if(key == "dealFastPay") {
                taPoliceSituationMonitoring.dealFastPay = taPoliceSituationMonitoring.dealFastPay?.plus(1)
                taPoliceSituationMonitoringTransaction.dealFastPay = 1
            }
            // 自行协商案件量
            if(key == "dealToNegotiate") {
                taPoliceSituationMonitoring.dealToNegotiate = taPoliceSituationMonitoring.dealToNegotiate?.plus(1)
                taPoliceSituationMonitoringTransaction.dealToNegotiate = 1
            }
            // 微信处理案件量
            if(key == "dealWechat") {
                taPoliceSituationMonitoring.dealWechat = taPoliceSituationMonitoring.dealWechat?.plus(1)
                taPoliceSituationMonitoringTransaction.dealWechat = 1
            }
            // 其他处理案件量
            if(key == "dealOthers") {
                taPoliceSituationMonitoring.dealOthers = taPoliceSituationMonitoring.dealOthers?.plus(1)
                taPoliceSituationMonitoringTransaction.dealOthers = 1
            }
            // 超时未接警数量
            if(key == "casesAcceptedCalledOvertime") {
                taPoliceSituationMonitoring.casesAcceptedCalledOvertime = taPoliceSituationMonitoring.casesAcceptedCalledOvertime?.plus(1)
                taPoliceSituationMonitoringTransaction.casesAcceptedCalledOvertime = 1
            }
            // 超时未出警数量
            if(key == "casesAcceptedOActionvertime") {
                taPoliceSituationMonitoring.casesAcceptedActionOvertime = taPoliceSituationMonitoring.casesAcceptedActionOvertime?.plus(1)
                taPoliceSituationMonitoringTransaction.casesAcceptedActionOvertime = 1
            }
            // 超时未处理数量(去除)
            if(key == "dealOvertime") {
                taPoliceSituationMonitoring.dealOvertime = taPoliceSituationMonitoring.dealOvertime?.plus(1)
                taPoliceSituationMonitoringTransaction.dealOvertime = 1
            }
            // 超时未上报数量(去除)
            if(key == "casesReportOvertime") {
                taPoliceSituationMonitoring.casesReportOvertime = taPoliceSituationMonitoring.casesReportOvertime?.plus(1)
                taPoliceSituationMonitoringTransaction.casesReportOvertime = 1
            }
            // 超期未结案数量
            if(key == "casesOpenedOvertime") {
                taPoliceSituationMonitoring.casesOpenedOvertime = taPoliceSituationMonitoring.casesOpenedOvertime?.plus(1)
                taPoliceSituationMonitoringTransaction.casesOpenedOvertime = 1
            }
            // 超期未关联案件数量(指是否已关联六合一案件)
            if(key == "casesRelatedOvertime") {
                taPoliceSituationMonitoring.casesRelatedOvertime = taPoliceSituationMonitoring.casesRelatedOvertime?.plus(1)
                taPoliceSituationMonitoringTransaction.casesRelatedOvertime = 1
            }
            // addTime
            if(key == "addTime") {
                taPoliceSituationMonitoring.addTime = Instant.now()
                taPoliceSituationMonitoringTransaction.addTime = Instant.now()
            }
            // addBy
            if(key == "addBy") {
                taPoliceSituationMonitoring.addBy = actionTagMap[key] as String?
                taPoliceSituationMonitoringTransaction.addBy = actionTagMap[key] as String?
            }
            // updateTime
            if(key == "updateTime") {
                taPoliceSituationMonitoring.updateTime = Instant.now()
                taPoliceSituationMonitoringTransaction.updateTime = Instant.now()
            }
            // updateBy
            if(key == "updateBy") {
                taPoliceSituationMonitoring.updateBy = actionTagMap[key] as String?
                taPoliceSituationMonitoringTransaction.updateBy = actionTagMap[key] as String?
            }
        }

        taPoliceSituationMonitoringTransactionMapper.insert(taPoliceSituationMonitoringTransaction)

        if(taPoliceSituationMonitoring.id!=null && !"".equals(taPoliceSituationMonitoring.id)) {
            var monitoringVoReflect = TaPoliceSituationMonitoringVo::class
            return taPoliceSituationMonitoringMapper.update(taPoliceSituationMonitoring)
        } else {
            return taPoliceSituationMonitoringMapper.insert(taPoliceSituationMonitoring)
        }
    }

//    override fun searchOvertimeResultList(map: Map<String, Any>?): List<Map<String, Object>> {
    override fun searchOvertimeResultList(map: Map<String, Any>?): List<TaPoliceSituationMonitoringVo?>? {
        try {
            return taPoliceSituationMonitoringMapper.searchOvertimeResultList(map)
        } catch (e: Exception) {
            log.info("searchOvertimeResultList: {}", e);
        }
        return emptyList();
    }

    override fun searchOvertimeOfTimeRangeResultList(map: HashMap<String, Any>?): List<TaPoliceSituationMonitoringVo?>? {
        try {
            return taPoliceSituationMonitoringMapper.searchOvertimeResultList(map)
        } catch (e: Exception) {
            log.info("searchOvertimeResultList: {}", e);
        }
        return emptyList();
    }

    override fun searchAverageActionTime(map: HashMap<String, Any>?): List<Map<String, Any?>?>? {
        try {
            if(map!=null && map.size>0) {
                var regionValLike = map?.get("regionId")?.let { taPoliceService.consRegion(it as String) } as String
                map["regionId"] = regionValLike
            }

            var accpetAvgTime: Int = 0
            var actionAvgTime: Int = 0

            var acceptCount: Int = 0
            var accpectAddTime: BigDecimal = BigDecimal.ZERO
            var acceptTime: BigDecimal = BigDecimal.ZERO

            var actionCount: Int = 0
            var actionAddTime: BigDecimal = BigDecimal.ZERO
            var actionDealTime: BigDecimal = BigDecimal.ZERO

            var dataList : List<Map<String, Any?>?>? = taPoliceSituationMonitoringMapper.searchBasicAverageActionTime(map)
            dataList?.forEach { it ->
                if(it?.get("add_time")!=null && it?.get("accept_time") != null) {
                    acceptCount += 1
                    accpectAddTime = accpectAddTime.add(BigDecimal(it?.get("add_time") as Long))
                    acceptTime = acceptTime.add(BigDecimal(it?.get("accept_time") as Long))
                }
                if(it?.get("action_time")!=null && it?.get("deal_time") != null) {
                    actionCount += 1
                    actionAddTime = actionAddTime.add(BigDecimal(it?.get("action_time") as Long))
                    actionDealTime = actionDealTime.add(BigDecimal(it?.get("deal_time") as Long))
                }
            }
            accpetAvgTime = acceptTime.subtract(accpectAddTime).divide(BigDecimal(acceptCount), 0, RoundingMode.HALF_UP).divide(BigDecimal(60), 0, RoundingMode.HALF_UP).setScale(0, BigDecimal.ROUND_HALF_UP).toInt()
            actionAvgTime = actionDealTime.subtract(actionAddTime).divide(BigDecimal(actionCount), 0, RoundingMode.HALF_UP).divide(BigDecimal(60), 0, RoundingMode.HALF_UP).setScale(0, BigDecimal.ROUND_HALF_UP).toInt()

            var resultList: List<Map<String, Any?>?>? = arrayListOf(mapOf<String, Any?>("accept_avg" to accpetAvgTime,
                    "action_avg" to actionAvgTime,
                    "diff_accept_second" to acceptTime.subtract(accpectAddTime).toInt(),
                    "accept_count" to acceptCount,
                    "diff_action_second" to actionDealTime.subtract(actionAddTime).toInt(),
                    "action_count" to actionCount
            ))

//            var resultList : List<Map<String, Any?>?>? = taPoliceSituationMonitoringMapper.searchAverageActionTime(map)
//            log.info("resultMap========>: {}", JSON.toJSONString(resultMap))
//            log.info("resultList========>: {}", JSON.toJSONString(resultList))
            return resultList
        } catch (e: Exception) {
            log.info("searchAverageActionTime: {}", e);
        }
        return emptyList();
    }

    override fun searchStatisticsOfActionIn24H(map: HashMap<String, Any>?) : List<Map<String, Any?>?>? {
        // 获取当天的零点
        val startToday: LocalDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN)
        // 获取当天结束时间
        val endToday: LocalDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX)
        var hourList: ArrayList<String>? = arrayListOf()
        val hourEnd = endToday.hour
        var hour = -1
        while (hour < hourEnd) {
            hour += 1
            hourList?.add(String.format("%02d", hour))
        }

        try {
            var regionValLike = map?.get("regionId")?.let { taPoliceService.consRegion(it as String) } as String
            map["regionId"] = regionValLike

            var resultList: ArrayList<Map<String, Any?>?>? = arrayListOf()
            var dataList: List<Map<String, Any?>?>? = taPoliceSituationMonitoringMapper.searchBasicStatisticsOfActionIn24H(map)
            hourList?.forEach { it ->
                var resultMap: HashMap<String, Any?>? = hashMapOf()
                var casesAcceptedCalled: Int = 0
                var casesAcceptedAction: Int = 0
                dataList?.forEach { d ->
                    casesAcceptedCalled += d?.get("casesAcceptedCalled") as Int
                    casesAcceptedAction += d?.get("casesAcceptedAction") as Int
                }
                resultMap?.put("hour", it)
                resultMap?.put("casesAcceptedCalled", casesAcceptedCalled)
                resultMap?.put("casesAcceptedAction", casesAcceptedAction)
                resultList?.add(resultMap)
            }
            return resultList
        } catch (e: Exception) {
            log.info("searchStatisticsOfActionIn24H: {}", e);
        }
        return emptyList();
    }

    override fun searchDistributionOfPolice(map: HashMap<String, Any>?): List<Map<String, Any?>?>? {
        try {
            var regionValLike = regionGlbmService.consRegion(map?.get("regionId") as String) as String
            var region = regionGlbmMapper.selectByPrimaryKey(map?.get("regionId") as String)
            val regionList: List<Map<String, Any?>?>? = regionGlbmService.searchRegionGlbm(mapOf("regionIdLike" to regionValLike, "level" to (Integer.valueOf(region.level) + 1)))

            var resultList: ArrayList<Map<String, Any?>?>? = arrayListOf()
            val dataList: List<Map<String, Any?>?>? = taPoliceSituationMonitoringTransactionMapper.searchBasicDistributionOfPolice(map)
            regionList?.forEach { it ->
                if("6115" != (it?.get("id") as String).substring(0, 4)) {
                    var casesAcceptedCalled: Int = 0
                    var casesAcceptedAction: Int = 0
                    var regionId: String = it?.get("id") as String
                    var regionLevel: String = it?.get("level") as String
                    dataList?.forEach { d ->

                        var xzqh: String = d?.get("xzqh") as String
                        var xzqhMatching: String = ""
                        if (regionLevel == "1") {
                            xzqhMatching = String.format("012d%", xzqh.substring(0, 2))
                        } else if (regionLevel == "2") {
                            if ("6113" == regionId.substring(0, 4)) {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 6))
                            } else if ("6115" == regionId.substring(0, 4)) {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 4))
                            } else {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 4))
                            }
                        } else {
                            if ("6115" == regionId.substring(0, 10)) {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 10))
                            } else {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 8))
                            }
                        }
                        if(regionId == xzqhMatching) {
                            casesAcceptedCalled += d?.get("casesAcceptedCalled") as Int
                            casesAcceptedAction += d?.get("casesAcceptedAction") as Int
                        }
                    }
                    var resultMap = hashMapOf(
                            "id" to it?.get("id"),
                            "name" to it?.get("name"),
                            "parent_id" to it?.get("parent_id"),
                            "level" to it?.get("level"),
                            "xzqh" to it?.get("id"),
                            "casesAcceptedCalled" to casesAcceptedCalled,
                            "casesAcceptedAction" to casesAcceptedAction
                    )
                    resultList?.add(resultMap)
                }
            }
            return resultList

        } catch (e: Exception) {
            log.info("searchDistributionOfPolice: {}", e);
        }
        return emptyList();
    }

    override fun searchDistributionOfPoliceAction(map: HashMap<String, Any>?): List<Map<String, Any?>?>? {
        try {
            var regionValLike = regionGlbmService.consRegion(map?.get("regionId") as String) as String
            var region = regionGlbmMapper.selectByPrimaryKey(map?.get("regionId") as String)
            val regionList: List<Map<String, Any?>?>? = regionGlbmService.searchRegionGlbm(mapOf("regionIdLike" to regionValLike, "level" to (Integer.valueOf(region.level) + 1)))

            var resultList: ArrayList<Map<String, Any?>?>? = arrayListOf()
            val dataList: List<Map<String, Any?>?>? = taPoliceSituationMonitoringTransactionMapper.searchBasicDistributionOfPoliceAction(map)
            regionList?.forEach { it ->
//                var resultMap: HashMap<String, Any?>? = hashMapOf()
                if("6115" != (it?.get("id") as String).substring(0, 4)) {
                    var casesAcceptedCalled: Int = 0
                    var casesAcceptedDeal: Int = 0
                    var regionId: String = it?.get("id") as String
                    var regionLevel: String = it?.get("level") as String
                    dataList?.forEach { d ->

                        var xzqh: String = d?.get("xzqh") as String
                        var xzqhMatching: String = ""
                        if (regionLevel == "1") {
                            xzqhMatching = String.format("012d%", xzqh.substring(0, 2))
                        } else if (regionLevel == "2") {
                            if ("6113" == regionId.substring(0, 4)) {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 6))
                            } else if ("6115" == regionId.substring(0, 4)) {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 4))
                            } else {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 4))
                            }
                        } else {
                            if ("6115" == regionId.substring(0, 10)) {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 10))
                            } else {
                                xzqhMatching = String.format("012d%", xzqh.substring(0, 8))
                            }
                        }
                        if(regionId == xzqhMatching) {
                            casesAcceptedCalled += d?.get("cases_accepted_called") as Int
                            casesAcceptedDeal += (
                                    d?.get("deal_accepted") as Int
                                    + d?.get("deal_fast_pay") as Int
                                    + d?.get("deal_to_negotiate") as Int
                                    + d?.get("deal_wechat") as Int
                                    + d?.get("deal_others") as Int
                                    + d?.get("") as Int
                                    )
                        }
                    }
                    var resultMap = hashMapOf(
                            "id" to it?.get("id"),
                            "name" to it?.get("name"),
                            "parent_id" to it?.get("parent_id"),
                            "level" to it?.get("level"),
                            "xzqh" to it?.get("id"),
                            "casesAcceptedCalled" to casesAcceptedCalled,
                            "casesAcceptedDeal" to casesAcceptedDeal
                    )
                    resultList?.add(resultMap)
                }
            }
            return resultList

        } catch (e: Exception) {
            log.info("searchDistributionOfPolice: {}", e);
        }
        return emptyList()
    }

    override fun searchNoticeMessage(map: HashMap<String, Any>?): List<Map<String, Any?>?>? {
        try {
            var regionValLike = map?.get("regionId")?.let { taPoliceService.consRegion(it as String) } as String
            map["regionId"] = regionValLike
            return taPoliceSituationMonitoringMapper.searchNoticeMessage(map)
        } catch (e: Exception) {
            log.info("searchNoticeMessage: {}", e);
        }
        return emptyList();
    }

    override fun searchRecentDeathSummary(map: HashMap<String, Any>?): List<Map<String, Any?>?>? {
        try {
            var regionValLike = map?.get("regionId")?.let { taPoliceService.consRegion(it as String) } as String
            map["regionId"] = regionValLike
            var result: List<Map<String, Any?>?>? = taPoliceSituationMonitoringMapper.searchRecentDeathSummary(map)
            var resultNew: List<HashMap<String, Any?>?>? = result as List<HashMap<String, Any?>?>?
            if(result!=null && result.size>0) {
                val accidentImage = TaAccidentImage()
                accidentImage.accidentId = result?.get(0)?.get("ta_accident_id") as Int?
                var imageList = accidentImageMapper.select(accidentImage)
                resultNew?.get(0)?.put("imageList", imageList)
            }
            return resultNew
        } catch (e: Exception) {
            log.info("searchRecentDeathSummary: {}", e);
        }
        return emptyList();
    }

    override fun searchDeathAccidentToday(map: HashMap<String, Any>?): List<Map<String, Any?>?>? {
        try {
            var regionValLike = map?.get("regionId")?.let { taPoliceService.consRegion(it as String) } as String
            map["regionId"] = regionValLike
            return taPoliceSituationMonitoringMapper.searchDeathAccidentToday(map)
        } catch (e: Exception) {
            log.info("searchDeathAccidentToday: {}", e);
        }
        return emptyList();
    }


}